/**
 * Created by hcadmin on 16/10/18.
 */
$(function(){
    //进入页面展示的数据
    var search;
    var key;

    var localstorage = window.localStorage;
    var keyword = localstorage.getItem("keyword");
    if (keyword != null && keyword.length > 0){

        search = "1";
        $(".search").val(keyword);
        $(".search").addClass('searching');
        //搜索
        initSearch(keyword);
    }else {
        //加载默认页面
        load();
    }
    //load();

    //var stop=true;//触发开关，防止多次调用事件
    //$(window).scroll(function() {
    //    //当内容滚动到底部时加载新的内容 100当距离最底部100个像素时开始加载.
    //    if ($(this).scrollTop() + $(document).height() +100>= $(document).height()) {
    //
    //        if (stop == true) {
    //            stop = false;
    //            load();
    //            if(search=="1"){
    //                initSearch(key);
    //            }
    //        }
    //    }
    //});
    function load(){
        //var timestamp = $(".tableview_cell1").last().attr("time")==undefined?0:$(".tableview_cell1").last().attr("time");

        initData("bigest_content",user_id,"3","3",0);
    }
   $(document).on('click','.tableview_cell1',function(){
       var approval_id = $(this).attr("id");

       if ($(".search").val().length > 0){
           localstorage.setItem("keyword",$(".search").val());
       }
       window.location.href="approvalDetail.html?index=3&id="+approval_id+"";
   });

    //点击  搜索
    $("#search").bind("input propertychange",function(){
        $(this).addClass('searching');
        key = $(this).val();
            $(".tableview_cell1").remove();
            search = "1";
            initSearch(key);
        if(key==""){
            $(this).removeClass('searching');
            localstorage.removeItem("keyword");
        }
    });
    function initSearch(keyword){
        //var timestamp = $(".tableview_cell1").last().attr("time")==undefined?0:$(".tableview_cell1").last().attr("time");
        initData("bigest_content",user_id,"3","3",0,"1",keyword);
    }
});